﻿using System;

namespace Patterns.Adapter {

    public class AbstractExample {

        public static void Run() {
            // Create adapter and place a request
            Target target = new Adapter();
            target.Request();
        }

        /// <summary>
        /// Defines the domain-specific interface that Client uses.
        /// </summary>
        private class Target {
            public virtual void Request() {
                Console.WriteLine("Called Target Request()");
            }
        }

        /// <summary>
        /// Adaps the interface Adaptee to the Target interface.
        /// </summary>
        private class Adapter : Target {
            private Adaptee adaptee = new Adaptee();

            public override void Request() {
                // Possibly do some other work
                // and then call SpecificRequest
                adaptee.SpecificRequest();
            }
        }

        /// <summary>
        /// Defines an existing interface that needs adapting.
        /// </summary>
        private class Adaptee {
            public void SpecificRequest() {
                Console.WriteLine("Called SpecificRequest()");
            }
        }
    }
}
